﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace cinetoona
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e)
        {
            
            
            //using (DataAccessDataContext cinetoonadb = new DataAccessDataContext())
            //{

            //}
            //if (username.Equals("cinetoona") && password.Equals("cinetoona"))
            //{
            //    bool authenticated = true;
            //    Session["IsAuthenticated"] = authenticated;
            //    Session["UserName"] = username;
                
            //    e.Authenticated = true;

            //    Response.Redirect("Home.aspx");
            //}
            //else
            //{
            //    Response.Redirect("Login.aspx");
            //}
        }

        protected void LoginUser_Authenticate(object sender, EventArgs e)
        {
            try
            {
                switch (LoginUser.UserName)
                {
                    case "cinetoona":
                        {
                            using (DataAccessDataContext cinetoonadb = new DataAccessDataContext())
                            {
                                var q = (from i in cinetoonadb.Logins
                                         where i.username == LoginUser.UserName && i.password == LoginUser.Password
                                         select i).Single();

                                if (LoginUser.Password.Equals(q.password))
                                {
                                    bool authenticated = true;
                                    Session["IsAuthenticated"] = authenticated;
                                    Session["UserName"] = LoginUser.UserName;
                                    Session["ConnectionString"] = ConfigurationManager.ConnectionStrings["pbasw_1ConnectionString"];

                                    Response.Redirect("Home.aspx");
                                }
                            }
                            break;
                        }
                    case "adultorama":
                        {
                            using (DataAccessDataContext adultoramadb = new DataAccessDataContext())
                            {
                                var q = (from i in adultoramadb.Logins
                                         where i.username == LoginUser.UserName && i.password == LoginUser.Password
                                         select i).Single();

                                if (LoginUser.Password.Equals(q.password))
                                {
                                    bool authenticated = true;
                                    Session["IsAuthenticated"] = authenticated;
                                    Session["UserName"] = LoginUser.UserName;
                                    Session["ConnectionString"] = ConfigurationManager.ConnectionStrings["pbasw_2ConnectionString"];

                                    Response.Redirect("Home.aspx");
                                }
                            }
                            break;
                        }
                }
            }
            catch
            {
                //Response.Redirect("Login.aspx");
            }
        }
    }
}
